﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using clf.weighing.entity;

namespace weighing
{
    /// <summary>
    ///  自定义备用磅单字段
    /// </summary>

    [Table(Name = "backup_bill_field", Comment = " 自定义备用磅单字段")]
    public class BackupBillFieldDao : BaseDao<BackupBillField>
    {
        #region instance

        private static BackupBillFieldDao? instance;
        public static BackupBillFieldDao Instance => instance ??= new BackupBillFieldDao();

        public override string GetTableName()
        {
            return TableName.backup_bill_field.ToString();
        }

        #endregion

        public bool IsExist(long id)
        {
            string condition = $"{BackupBillColumns.id} = {id} ";
            string sql = SqlBuilder.GetSelectSql(GetTableName(), "id", condition);
            var data = Sqlite.Select<BackupBillField>(sql);
            return data.Any();
        }

        public List<BackupBillField> SelectAllByType(int? type)
        {
            if (type == null)
            {
                throw new ArgumentNullException($"过磅类型{type} 不支持。");
            }
            string condition = $"{BackupBillColumns.bill_type} = {type} ";
            string orderby = $" {BackupBillColumns.sort} asc ";
            string sql = SqlBuilder.GetSelectSql(GetTableName(), null, condition, null, null, orderby);
            var data = Sqlite.Select<BackupBillField>(sql);
            return data;
        }
    }
}
